package DMSXL._2024.BinaryTrees;

public class isValidBST {
    public static void main(String[] args) {
        Integer[] nums = {2,1,3};
        TreeNode root = CreateTree.createBinaryTree(nums,0);
        System.out.println(new isValidBST().isValidBST(root));
    }
    long max = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root == null){
            return true;
        }
        boolean left = isValidBST(root.left);
        if(max < root.val){
            max = root.val;
        }else {
            return false;
        }
        boolean right = isValidBST(root.right);
        return left && right;
    }
}
